package com.teamclub.domain.system;


import com.google.common.collect.Lists;
import io.ebean.Ebean;
import io.ebean.Finder;
import io.ebean.Model;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.util.Date;
import java.util.List;

/**
 * Created by ilkkzm on 17-4-24.
 */
@Entity
@NoArgsConstructor
@Data
@EqualsAndHashCode(callSuper = false)
public class AppSubjectUser extends Model {
    @Id
    private Integer id ;

    private String userName;

    private String realName;

    private String telephone;

    private String email;

    private String appDomain;

    private String userPassword;

    private String organNo; //所属

    private Integer roleId; //所属角色

    private Integer archId; //所属组织

    private Boolean isAdmin; //是否管理员

    private Date validateDate; //有效期

    private Integer status;

    @Transient
    private String roleName; //角色名称

    @Transient
    private String archName; //组织机构名称

    public static Finder<Integer, AppSubjectUser> finder = new Finder<>(AppSubjectUser.class);

    public String getRoleName() {
        if(roleId == null) { return ""; }
        AppRole appRole = Ebean.find(AppRole.class, roleId);
        return appRole == null ? "" : appRole.getName();
    }

    public String getArchName() {
        if(archId == null) { return ""; }
        AppOrgArch arch = Ebean.find(AppOrgArch.class, archId);
        return arch == null ? "" : arch.getArchName();
    }
    public AppSubjectUser(Integer id, String userName, String realName, String userPassword) {
        this.id = id;
        this.userName = userName;
        this.realName = realName;
        this.userPassword = userPassword;
    }

}
